package com.zr.gdms.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.gdms.dao.UserDao;
import com.zr.gdms.model.User;
import com.zr.gdms.util.JDBCUtil;
/**
 * 用户逻辑实现层
 * @author 李培宁
 *
 */
public class UserDaoImpl implements UserDao{

	@Override
	public User getUserByUnameAndUpsw(String uname, String upsw) {
		User u = new User();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT `user`.uid,`user`.uname,`user`.upsw,user.fid");
		sql.append(" FROM `user`");
		sql.append(" WHERE `user`.uname=? AND upsw=?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setString(1, uname);
			pst.setString(2, upsw);
			
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				u.setUid(rs.getInt("uid"));
				u.setUname(rs.getString("uname"));
				u.setUpsw(rs.getString("upsw"));
				u.setFid(rs.getInt("fid"));
			}
			JDBCUtil.closeJDBC(pst, con);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return u;
	}

}
